package com.aopdemo;

import com.aopdemo.config.AppConfig;
import com.aopdemo.service.OrderService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class MainApp {
    public static void main(String[] args) {
        // 初始化Spring容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

        // 获取订单服务Bean
        OrderService orderService = context.getBean(OrderService.class);

        System.out.println("===== 测试add方法 =====");
        try {
            orderService.add("苹果", 5);
        } catch (Exception e) {
            System.out.println("捕获异常: " + e.getMessage());
        }

        System.out.println("\n===== 测试delete方法 =====");
        try {
            orderService.delete("香蕉");
        } catch (Exception e) {
            System.out.println("捕获异常: " + e.getMessage());
        }

        System.out.println("\n===== 测试find方法 =====");
        orderService.find("橙子");

        // 关闭容器
        context.close();
    }
}
